package paper.dao.impl;

import java.util.List;

import keter.dao.base.KeterAbstractDao;

import org.springframework.stereotype.Repository;

import paper.dao.PaperDao;
import paper.domain.AuditStatus;
import paper.domain.Paper;

@Repository
public class PaperDaoImpl extends KeterAbstractDao<Paper> implements PaperDao {
	
    /**
     * <p>Method ：findByMaster
     * <p>Description : （老师）查看查看自己负责确定的课题
     *
     * @param id
     * @return 
     * @see paper.dao.TopicDao#findSubmitOrPassByMaster(java.lang.Long)
     */
    @Override
    public List<Paper> findSubmitOrPassByMaster(Long id) {
    	//当前用户是负责人且状态为“提交”的课题
        return getResultList("from Paper t where t.master.id = :id "
        		+ "and t.status='submit' or t.status='pass' "
        		+ "order by t.submitted desc", 
				wrap("id"),
				wrap(id));
    }
    
    @Override
    public List<Paper> findByCreator(Long id) {
       return getResultList("from Paper t where t.creator.id = :id order by created desc", 
              wrap("id"),
              wrap(id));
    }
 

    /**
     * <p>Method ：submitTopic
     * <p>Description : (学生)提交课题
     *
     * @param id 
     * @see paper.dao.TopicDao#submitTopic(java.lang.Long)
     */
    @Override
    public void submit(Paper paper) {
    	paper.setStatus(AuditStatus.SUBMIT.toString());
        save(paper);
    }
}